import screen from './screen.js'
import ctrls from './ctrls.js'
import list from './list.js'

let addDiv = document.getElementById("add-popup");
let addBtn = document.getElementById("add-div-add-btn");
let addInput = document.getElementById("addInput");

export default {
	init() {
		addBtn.addEventListener("click", () => {
			let value = addInput.value;
			if(value.trim() == "") {
				return
			}

			let id = ctrls.getCtrlId();
			list.addResource(id, value);

			addDiv.style.display = "none";
		})
	},
	show(x, y) {
		let height = screen.getWh().windowHeight;

		if(y + 50 + 240 > height) {
			console.log(y)
			addDiv.style.top = y - 190 + "px";
			addDiv.classList.add("bottom")
		} else {
			addDiv.style.top = y + 50 + "px";
			addDiv.classList.remove("bottom")
		}

		addDiv.style.left = x - 20 + "px";
		addDiv.style.display = "block";

		addInput.focus();
	}
}